package com.kennedy.atoupdate.service;

import com.github.pagehelper.PageHelper;
import com.kennedy.atoupdate.beans.GroupInfo;
import com.kennedy.atoupdate.beans.VersionInfo;
import com.kennedy.atoupdate.mapper.GroupInfoMapper;
import com.kennedy.atoupdate.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by tao.zeng on 2017/8/17.
 */
@Service
public class GroupInfoService {
    @Autowired
    private GroupInfoMapper groupInfoMapper;

    public List<GroupInfo> getListByPage(GroupInfo group) {
        if (group.getOffset() != null && group.getLimit() != null) {
            PageHelper.offsetPage(group.getOffset(), group.getLimit());
        }
        List<GroupInfo> groups = groupInfoMapper.selectAll();
        return groups;
    }

    public void delete(Long id) {
        groupInfoMapper.deleteByPrimaryKey(id);
    }

    public void insert(GroupInfo groupInfo) {
        groupInfo.setCreateTime(DateUtil.getCurrentTime());
        groupInfoMapper.insert(groupInfo);
    }

}
